package googleJam.round1B;

import googleJam.problem.CaseTest;

public class RoundBCaseTest extends CaseTest {

	private int [][] _results;
	private Team[] _teams;

	public RoundBCaseTest(String beginLine, int index, int beginIndex) {
		super(beginLine, index, beginIndex);
	}

	@Override
	public int calculLineNumber() {
		return Integer.valueOf(_beginLine);
	}

	public int getEndIndex()
	{
		return _beginIndex + getNumberLine();
	}

	@Override
	public String getResult() {
		return null;
	}

	@Override
	public void trait(String line, int index) {
		if(index == 0)
		{
			int teamNb = Integer.valueOf(line);
			_results = new int  [teamNb][teamNb];
			_teams = new Team[teamNb];
			for(int i = 0 ; i< teamNb; i ++)
			{
				_teams [i] = new Team(i, _results, _teams);
			}
		}
		else
		{
			for(int i= 0; i < line.length(); i ++)
			{
				if(i > (index - 1))
				{
					if(line.charAt(i) == '.')
					{
						_results[index-1][i] = -1;
					}
					else
					{
						_results[index-1][i] = Integer.valueOf(line.charAt(i));
					}
				}
			}


		}

		if ((index+1) == getNumberLine())
		{
			int teamNB = _results.length;
			double [] wps = new double[teamNB];
			for(int i= 0; i < line.length(); i ++)
			{
				if(i > (index - 1))
				{
					double s = 0;
					int oponentNb = 0;
					if(_results[index - 1][i] != -1)
					{
						s += _results[index - 1] [i];
						oponentNb ++;
					}
					wps [index-1] = s/oponentNb;
					System.out.println("case "+_caseIndex +" "+wps[index-1]);
					
				}
			}

		}
	}


}
